package com.gitee.wsl.ext.collection


inline fun <K, E> Iterable<E>.strictAssociateBy(crossinline keyExtractor: (E) -> K): Map<K, E> {
    return mapFrom(
        map {
            keyExtractor(it) to it
        }
    )
}

inline fun <K, E> Sequence<E>.strictAssociateBy(crossinline keyExtractor: (E) -> K): Map<K, E> {
    val map = mutableMapOf<K, E>()
    var count = 0
    forEach {
        map[keyExtractor(it)] = it
        count++
    }
    require(map.size == count)
    return map
}
